#! /bin/bash
echo "执行脚本重启tomcat";
echo “关闭tomcat”;
TOMCAT="/usr/local/tomcat"
ps -ef | grep local/tomcat | grep -v grep > /dev/null
if [ $? -eq 0 ]; then 
	echo “1,执行正常关闭的脚本程序”；
	# echo ${TOMCAT}	
	`bash ${TOMCAT}/bin/shutdown.sh`
        sleep 3s 	
	# grep -v grep 排除掉字段中含有grep的进程
	ps -ef | grep ${TOMCAT} | grep -v grep > /dev/null 
	if [ $?  -eq 0 ]; then 
		echo "仍有tomcat程序存在";
		echo “执行强制关闭进程”;
		PID=`ps -ef | grep  ${TOMCAT} | grep -v grep | awk '{print $2}'`
		echo ${PID}
		kill -9 ${PID}	
		sleep 5s
	fi
fi
echo “开始重启tomcat”
bash ${TOMCAT}/bin/startup.sh
ps -ef | grep ${TOMCAT} | grep -v grep > /dev/null
if [$? -eq 0]; then 
	echo "重启tomcat服务成功"
fi
